package com.qixiucoding.link.inherit.field;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qixiucoding.link.AbstractLink;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author longhj
 * @Description 字段处理2
 * @Date 2021/10/15 星期五 0:08
 */
@Component
@Scope(value = "prototype")
public class FieldF2Inherit extends AbstractLink {
    @Override
    public JSONArray doDeal(JSONArray jsonArray) {
        List<JSONObject> collect = jsonArray.stream().map(e -> {
            JSONObject o = (JSONObject) JSONObject.toJSON(e);
            String jack = o.getString("john");
            System.out.println("john:"+jack);
            o.put("john", "我更新了！");
            return o;
        }).collect(Collectors.toList());
        JSONArray ja = JSONArray.parseArray(JSON.toJSONString(collect));
        return ja;
    }
}
